package helpers;

import java.util.Date;

public class IdUniqueHelper {
	private static final String ALPHABET  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";//"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final long    BASE     = 36;

    public static String encode(long num)
    {
        StringBuilder sb = new StringBuilder();

        while ( num > 0 )
        {
            sb.append( ALPHABET.charAt((int) (num % BASE) ) );
            num /= BASE;
        }

       return sb.reverse().toString();   
    }

    public static long decode(String str)
    {
        long num = 0;

        for ( int i = 0, len = str.length(); i < len; i++ )
        {
            num = num * BASE + ALPHABET.indexOf( str.charAt(i) ); 
        }

        return num;
    }   
    
    public static String getId() {
    	/*Date date = new Date();
    	String id = encode(date.getTime());*/
    	
    	long time = System.nanoTime();
    	String id = encode(time);
    	
    	return id;
    }
}
